package com.zs.cat.cms;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

/**
 * Created by weilingfeng on 2016/6/2.
 */
public class MainClass implements Watcher {

    public static String ZOOKEEPER_URL = "127.0.0.1:2181";

    protected static CountDownLatch countDownLatch=new CountDownLatch(1);

    public static int TIME_OUT = 1000 * 60 * 2;

    public static void main(String[] args) throws IOException, InterruptedException {
        ZooKeeper zooKeeper = new ZooKeeper(ZOOKEEPER_URL, TIME_OUT, new MainClass());
        System.out.println("ok");
        countDownLatch.await();
        String str = "zookeeper://127.0.0.1:2181";
        System.out.println(str.substring(str.indexOf("//")+2));
    }

    @Override
    public void process(WatchedEvent event) {
        if(event.getState()== Event.KeeperState.SyncConnected){
            System.out.println("connected");
            countDownLatch.countDown();
        }
    }
}
